
const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

const coupon_image = "";

const getInfo = data => {
  return new Promise(function (resolve, reject) {
    wx.showToast({
      title: '拼命加载中',
      icon: 'loading',
      success() {
        //网络请求
        wx.request({
          url: 'https://wxb.whwangdoudou.cn/pdd.php',
          data: data,
          method: 'POST',
          header: {
            'Content-Type': 'application/x-www-form-urlencoded'
          },
          success: function (res) {
            // success网络请求成功
            if (res.statusCode != 200) {
              reject({ error: '服务器忙，请稍后重试', code: 500 });
              return;
            }
            resolve(res.data);
            wx.hideToast();
          },
          fail: function (res) {
            reject({ error: '网络错误', code: 0 });
          }
        })
      }
    })
  })
}





module.exports = {
  formatTime: formatTime,
  getInfo: getInfo,
  coupon_image: coupon_image
}
